package com.aube.video;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;

import com.android.volley.Response;
import com.aube.AubeApplication;
import com.aube.activity.WapActivity;
import com.aube.push.PushSetting;
import com.huyn.baseframework.dynamicload.CanCloseLayout;
import com.huyn.baseframework.dynamicload.DLBridge;
import com.huyn.baseframework.dynamicload.OnShareChannelSelected;
import com.huyn.baseframework.model.Category;
import com.huyn.baseframework.model.ChannelDetail;
import com.huyn.baseframework.net.BFJSONRequest;
import com.huyn.baseframework.net.HttpRequestLoader;
import com.huyn.baseframework.share.ShareModule;
import com.huyn.baseframework.share.ShareUtil;
import com.huyn.baseframework.utils.StringUtils;
import com.huyn.baseframework.utils.UserUtil;
import com.ryg.dynamicload.DLProxyFragmentActivity;
import com.ryg.dynamicload.internal.DLIntent;
import com.ryg.dynamicload.internal.DLPluginManager;

import java.util.HashMap;

/**
 * Created by huyaonan on 16/9/22.
 */
public class SimpleBridge implements DLBridge {
    
    private PlayActivity mPlayActivity;
    
    public SimpleBridge(PlayActivity mPlayActivity) {
        this.mPlayActivity = mPlayActivity;
    }

    @Override
    public void onClickToVideo(ChannelDetail channelDetail) {
        Intent intent = new Intent(mPlayActivity, PlayActivity.class);
        intent.putExtra(PlayActivity.CHANNEL_ITEM, channelDetail);
        mPlayActivity.startActivity(intent);
    }

    @Override
    public void onClickToVideo(ChannelDetail channelDetail, Category category) {
        Intent intent = new Intent(mPlayActivity, PlayActivity.class);
        intent.putExtra(PlayActivity.CHANNEL_ITEM, channelDetail);
        intent.putExtra(PlayActivity.CATEGORY_ITEM, category);
        mPlayActivity.startActivity(intent);
    }

    @Override
    public void onClickToWap(String title, String url, boolean post) {
        Intent intent = new Intent(mPlayActivity, WapActivity.class);
        intent.putExtra(WapActivity.WEB_TITLE, title);
        intent.putExtra(WapActivity.WEB_URL, url);
        intent.putExtra(WapActivity.WEB_POST, post);
        mPlayActivity.startActivity(intent);
    }

    @Override
    public void reportUmengEvent(String id, String value) {
        mPlayActivity.reportUmengEvent(id, value);
    }

    @Override
    public void openPluginActivity(DLIntent intent) {
        DLPluginManager.getInstance(mPlayActivity).startPluginActivity(mPlayActivity, intent, DLProxyFragmentActivity.class);
    }

    @Override
    public boolean isUserLogin() {
        return UserUtil.isUserLogin();
    }

    @Override
    public void doUserLogin() {

    }

    @Override
    public void loginByChannel(int channel) {

    }

    @Override
    public void doShare(ShareModule shareModule) {

    }

    @Override
    public void shareWeiboVideo(String url, String content, Bitmap bitmap) {

    }

    @Override
    public void shareWeiboImg(String path, String content) {

    }

    @Override
    public boolean isWxInstalled() {
        return ShareUtil.isWXAppInstalled();
    }

    @Override
    public void exeHttpRequest(HashMap<String, String> params, Class modelClass, String TAG, Response.Listener listener) {
        BFJSONRequest request = new BFJSONRequest(modelClass, params, listener);
        if(StringUtils.isNotBlank(TAG))
            request.setTag(TAG);
        HttpRequestLoader.getInstance(mPlayActivity).startHttpLoader(request);
    }

    @Override
    public View getRootView() {
        return mPlayActivity.getBaseRootView();
    }

    @Override
    public void tooglePush() {
        if(PushSetting.isPushOn(mPlayActivity)) {
            PushSetting.unregistPush(mPlayActivity);
        } else {
            PushSetting.registPush(mPlayActivity);
        }
    }

    @Override
    public boolean isPushOn() {
        return PushSetting.isPushOn(mPlayActivity);
    }

    @Override
    public void showShareLayout(OnShareChannelSelected selector) {

    }

    @Override
    public void registToReceiveKeyBackGroup(CanCloseLayout layout) {

    }

    @Override
    public void onReady() {

    }
}
